package cn.qf.shop.service.impl;

import cn.qf.shop.mapper.ComplaintsMapper;
import cn.qf.shop.pojo.entity.Complaints;

import cn.qf.shop.pojo.qo.ComplaintsQO;
import cn.qf.shop.service.ComplaintsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
@Transactional(propagation = Propagation.REQUIRES_NEW)
public class ComplaintsServiceImpl  implements ComplaintsService {
    private Logger logger = LoggerFactory.getLogger(ComplaintsServiceImpl.class);
    @Resource
    ComplaintsMapper complaintsMapper;
    public int addComp(ComplaintsQO complaintsQO) {
        Complaints complaints = new Complaints();
        BeanUtils.copyProperties(complaintsQO,complaints);
        int i = complaintsMapper.insertComp(complaints);
        return i;
    }

    public int updateComp(ComplaintsQO complaintsQO) {
        Complaints complaints = new Complaints();
        BeanUtils.copyProperties(complaintsQO,complaints);
        int i = complaintsMapper.updateComp(complaints);
        return i;
    }

    public int deleteComp(int compId) {
        int i = complaintsMapper.deleteComp(compId);
        return i;
    }

    public int deleteAllComp(List<Integer> compIds) {
        int i = complaintsMapper.deleteAllComp(compIds);
        return i;
    }

    public List<Complaints> showComp() {
        List<Complaints> complaints = complaintsMapper.showAll();
        return complaints;
    }

    public List<ComplaintsQO> COMPLAINTSList(String keyword, String createTime, String updateTime, int limit, int offset) {
        List<Complaints> complaints = complaintsMapper.selectAll(keyword, createTime, updateTime, (limit - 1) * offset, offset);
        if (complaints == null) {
            return  null;
        }else {
            List<ComplaintsQO> complaintsQOS = new ArrayList();
            for (Complaints complaints1:complaints) {
                ComplaintsQO complaintsQO = new ComplaintsQO();
                BeanUtils.copyProperties(complaints1,complaintsQO);
                complaintsQOS.add(complaintsQO);
            }
            return  complaintsQOS;
        }
    }
}
